<?php
$this->headLink()->appendStylesheet($this->js('css/jquery.alerts.css'))
->appendStylesheet($this->js('css/ui.checkbox.css'))
->appendStylesheet($this->js('css/tablesorter/default.css'))
->appendStylesheet($this->Css('table.css'));
$this->headScript()->appendFile($this->js('jquery-ui/ui/jquery.ui.draggable.js'))
->appendFile($this->js('jquery-ui/ui/jquery.ui.resizable.js'))
->appendFile($this->js('plugins/jquery.tablesorter.js'))
->appendFile($this->js('jquery-ui/ui/jquery.ui.dialog.js'));
?>
<script>
$(function() {
//    $("#datepicker").datepicker( {dateFormat: 'yy-mm-dd' });
    $("#dialog").dialog({
            bgiframe: true,
            autoOpen: false,
            width:600,
            height: 500,
            modal: true
        });
    $("#data-area a").click(function(){
        var id= $(this).attr('id');
        $.get("<?php echo $this->route('get-detail')?>" ,{id:id},
            function(data){
            $("#sel-content").html(data);
            $("#dialog").dialog('open');
            });
        });
});
</script>
<style>
#listTable {text-align:center;margin:5px auto; width:98%}
#listTable td ,#listTable th {padding:3px;white-space: nowrap;}
#select-area {margin:auto; text-align:center}
#sTable {margin:auto; width:98%}
#sTable  td {
border-right:1px dashed #66CCFF;
color:#666699;
padding:10px 20px;}
</style>
<div id="select-area">
<span style="margin-right:20px"><?php echo $this->translate('standard semester')?> :  <b><?php echo $this->Semester['year']?></b></span>
</div>
<div id="data-area">
<table border="1" id="listTable" class="newspaper-a">
<thead>
<tr>
<th colspan="2"></th>
<th><?php echo $this->translate('total')?></th>
<?php $temp=0;?>
<?php foreach($this->tolYear as $i=>$val):?>
<?php if ($i=='all') continue;?>
<?php $t_year = $this->Semester['year']-$i;
    $temp_md = explode("-",$this->defaultAgeDate);
    $temp_next = date ("Y-m-d", mktime (0,0,0,$temp_md[0],$temp_md[1]-1,$t_year+1912));
    $next_year  = explode("-",$temp_next);
 ?>
<th>
<?php if ($temp++==0):?>
<?php echo  sprintf('未滿%d足歲<br>%d年%d月%d日<br>以後出生',$i,$t_year,$temp_md[0],$temp_md[1])?>
<?php else:?>
<?php echo  sprintf('%d至未滿%d歲<br>%d年%d月%d日<br>至%d年%d月%d日',$i-1,
$i,$t_year,$temp_md[0],$temp_md[1],$t_year+1,$next_year[1],$next_year[2])?>
<?php endif?>
</th>
<?php endforeach?>
</tr>
</thead>
<tbody>
<?php for ( $sex=0 ; $sex<=2 ; $sex++):?>
    <tr>
    <?php if ($sex==0):?>
     <th rowspan="3" ><?php echo $this->translate('count')?></th>
     <th><?php echo $this->translate('subtotal')?></th>
     <td><?php echo $this->tolYear['all']?></td>
     <?php else:?>
    <th><?php echo $this->translate($this->sexName[$sex])?></th>
    <td><?php echo $this->tolAll[$sex]?></td>
    <?php endif;?>
   <?php foreach($this->tolYear as $i=>$val):?>
    <?php if ($i=='all') continue;?>
        <?php if ($sex==0):?>
            <td><?php if($this->tolYear[$i]):?>
            <a href="#" id="total-<?php echo $i?>-<?php echo $sex?>"><?php echo $this->tolYear[$i]?></a>
            <?php else:?>&nbsp;<?php endif?>
            </td>
        <?php else:?>
                 <td><?php if( isset($this->tolSex[$i][$sex])):?>
                 <a href="#" id="total-<?php echo $i?>-<?php echo $sex?>"><?php echo $this->tolSex[$i][$sex]?></a>
                 <?php else: ?>&nbsp;<?php endif?>
                 </td>
         <?php endif?>
    <?php endforeach?>
    </tr>
<?php endfor?>

<?php $className = $this->ClassGrade();?>
<?php foreach($this->listArr as $i=>$arr):?>
<tr >
<?php for ( $sex=1 ; $sex<=2 ; $sex++):?>
        <?php if ($sex==1):?>
            <th rowspan="2"><?php echo $className[$i] ?></th>
         <?php endif?>
            <th><?php echo $this->translate($this->sexName[$sex])?></th>
          <?php foreach($this->tolYear as $id=>$val):?>
          <td>
          <?php if ($id == 'all'):?>
           <a href="#" id="detail-<?php echo $id?>-<?php echo $sex?>-<?php echo $i?>"><?php echo $this->tolYearClass[$i][$sex]?></a>
           <?php else:?>
           <?php if (isset($arr[$sex][$id])):?>
           <a href="#" id="detail-<?php echo $id?>-<?php echo $sex?>-<?php echo $i?>"><?php echo $arr[$sex][$id]?></a>
           <?php else:?>&nbsp;<?php endif?>
           <?php endif;?>
           </td>
         <?php endforeach;?>
         </tr>
    <?php endfor;?>

<?php endforeach;;?>
   </tbody>
</table>
</div>

<div id="dialog" title="<?php echo $this->translate('students list')?>">
    <div id="sel-content"></div>
</div>